appium报错, ANDROID 您所在的位置:网站首页 appium driverwindow_handles报错 appium报错, ANDROID

appium报错, ANDROID

2024-07-16 06:53| 来源: 网络整理| 查看: 265

一、appium报错, ANDROID_HOME is set but does not exist on the file system at “D:\android-sdk;

在cmd命令行输入:appium-doctor 

报错:ANDROID_HOME is set but does not exist on the file system at "D:\android-sdk;"或者其他类似问题

查看ANDROID_HOME是否添加在用户变量这里;

path中是否添加:

path中是否添加

二、Appium运行时,error: Logcat capture failed: spawn ENOENT的解决办法

我在我的电脑上已经设置环境变量了啊。并且可以正常执行adb命令,为什么appium识别不到呢?难道需要在appium里单独设置吗?

重启appium,问题解决,不再报错了。

三、 error: Failed to start an Appium session, err was: Error: Command failed: C:\Windows\system32\cmd.exe /s /c "D:\android-sdk\platform-tools\adb.exe -s 127.0.0.1:16384 shell "ps 'uiautomator'"" > ps: bad uiautomator

原因:

对应执行的指令是ps ‘uiautomator’,Android7不支持这个指令格式,所以执行结果是bad pid ‘uiautomator’; 目前Appium未对此进行处理,所以需要修改此指令的执行方式。

解决方法:

1、从目录Appium的安装目录\Appium\node_modules\appium\node_modules\appium-adb\lib找到文件adb.js。 2、修改代码:

ADB.prototype.shell = function (cmd, cb) {

  if (cmd.indexOf('"') === -1) {

    cmd = '"' + cmd + '"';

  }

  var execCmd = 'shell ' + cmd;

   this.exec(execCmd, cb);

 };

在上面的代码段下方添加代码段:

ADB.prototype.shell_grep = function (cmd, grep, cb){

   if (cmd.indexOf('"') == -1){

     cmd = '"' + cmd + '"';

   }

  var execCmd = 'shell' + cmd + '| grep ' + grep;

   this.exec(execCmd, cb);

 };

修改代码:

 ADB.prototype.getPIDsByName = function (name, cb) {  logger.debug("Getting all processes with '" + name + "'");  this.shell("ps '" + name + "'", function (err, stdout) {  if (err) return cb(err);  stdout = stdout.trim();  var procs = [];  var outlines = stdout.split("\n");  _.each(outlines, function (outline) {  if (outline.indexOf(name) !== -1) {  procs.push(outline);  }  });  if (procs.length < 1) {  logger.debug("No matching processes found");  return cb(null, []);  }  var pids = [];  _.each(procs, function (proc) {  var match = /[^\t ]+[\t ]+([0-9]+)/.exec(proc);  if (match) {  pids.push(parseInt(match[1], 10));  }  });  if (pids.length !== procs.length) {  var msg = "Could not extract PIDs from ps output. PIDS: " +  JSON.stringify(pids) + ", Procs: " + JSON.stringify(procs);  return cb(new Error(msg));  } cb(null, pids);  });  };

将上方代码段注释掉,新增下方的代码段:

ADB.prototype.getPIDsByName = function (name, cb) { logger.debug("Getting all processes with '" + name + "'"); this.shell_grep("ps", name, function (err, stdout) { if (err) { logger.debug("No matching processes found"); return cb(null, []); } var pids = []; _.each(procs, function (proc) { var match = /[^\t ]+[\t ]+([0-9]+)/.exec(proc); if (match) { pids.push(parseInt(match[1], 10)); } }); if (pids.length !== procs.length) { var msg = "Could not extract PIDs from ps output. PIDS: " + JSON.stringify(pids) + ", Procs: " + JSON.stringify(procs); return cb(new Error(msg)); } cb(null, pids); }); };



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有